package com.pattern.design.designpattern.databind;

import android.app.Activity;
import android.view.View;

import androidx.databinding.ViewDataBinding;

import com.pattern.design.designpattern.R;
import com.pattern.design.designpattern.databinding.UserItemBinding;




public class UserAdapter extends RecyclerAdapter<UserBean,UserItemBinding>{
    private BindingItemListen  itemListen;
    public UserAdapter(Activity context,
                            BindingItemListen<UserBean,UserItemBinding> itemListen) {
        super(context);
        this.itemListen = itemListen;
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.user_item;
    }

    @Override
    protected void onBindItem(final UserItemBinding binding, final UserBean userBean, final int position) {
        binding.setUserbean(userBean);
        binding.executePendingBindings();
        binding.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemListen.onItemClick(binding,userBean,position);
            }
        });
    }

    @FunctionalInterface
    public interface BindingItemListen<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);
    }

}